package com.baizhi.lql.controller;

import com.baizhi.lql.dto.Dto;

import com.baizhi.lql.entity.Category;
import com.baizhi.lql.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
// 一级
    @RequestMapping("queryOnePage")
    @ResponseBody
    public Map<String,Object> queryOnePage(@RequestBody Dto dto){
        return categoryService.queryPage(dto.getPage(), dto.getPageSize());
    }
    @RequestMapping("queryOne")
    @ResponseBody
    public Category queryOne(int id){
        return categoryService.queryOne(id);
    }
    @RequestMapping("modify")
    @ResponseBody
    public void modify(@RequestBody Category category){
        categoryService.modify(category);
    }
   /* @RequestMapping("del")
    @ResponseBody
    public Map<String,Object> del(@RequestBody Dto dto, @RequestParam (required = false) int parentId){
        return categoryService.remove(dto.getId(),parentId);
    }*/
    @RequestMapping("reg")
    @ResponseBody
    public void reg(@RequestBody Category category){
        categoryService.reg(category);
    }

    // 二级
    @RequestMapping("queryTwoPage")
    @ResponseBody
    public Map<String,Object> queryTwoPage(@RequestBody Dto dto){
        return categoryService.queryTwoPage(dto.getPage(), dto.getPageSize(),dto.getCategoryId());
    }

    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public List<Category> queryByLevelsCategory(){
        return categoryService.queryByLevelsCategory();
    }
}
